<template>
	<view class="content">
		<view style="padding: 14rpx;">
			<uni-row class="demo-uni-row">
				<uni-col :span="7">
					<uni-data-select v-model="parameter.Category" :localdata="options"
						@change="change"></uni-data-select>
				</uni-col>
				<uni-col :span="14">
					<view style="margin-left: 8rpx;">
						<uni-easyinput prefixIcon="search" class="uni-mt-5" trim="all" v-model="inputVal"
							placeholder="请输入内容" @input="input($event)"></uni-easyinput>
					</view>
				</uni-col>
				<uni-col :span="3">
					<view style="icon" @click="onClickScan">
						<image src="../../../static/saoma.png" mode=""></image>
					</view>
				</uni-col>
			</uni-row>
		</view>


		<view style="background-color: #999;">
			<uni-card :is-shadow="false" is-full v-for="(item,index) in formData" :key="index">
				<view class="forms_rows">
					<view>
						<view class="forms_label">
							药品名称： {{item.name}}
						</view>
						<view>
							<view class="forms_label">
								规格：{{item.specification}}
							</view>
						</view>
						<view class="forms_label" style="color: red;">
							库存：{{item.stockQty}}
						</view>
						<view class="forms_label">
							生产厂家：{{item.manufacturer}}
						</view>
					</view>
					<view class="froms_icons">
						<button type="primary" size="mini" @click="details(item)">
							盘点
						</button>
					</view>

				</view>
			</uni-card>

		</view>
	</view>
</template>

<script setup>
	import {
		onReachBottom,
	} from '@dcloudio/uni-app';
	import {
		reactive,
		ref
	} from "vue";
	import getOptions from "@/utils/options/getSelectList.js"
	import {
		getpProcurement
	} from "./request.js"

	const value = ref(0)
	const inputVal = ref("")

	const options = ref([])



	getOptions('GetValueList', options, ['DRUGTYPE'], 'post').then((res) => {
		options.value = res
	})
	const parameter = reactive({
		current: 1,
		size: 10,
		searchKey: "",
		Category: null,
	})

	const formData = ref([])

	const request = (e) => {
		getpProcurement(parameter).then((res) => {
			if (e === false) {
				formData.value = res.data.records
				return
			}
			formData.value = [...formData.value, ...res.data.records]
		})
	}
	request()


	const change = () => {
		parameter.current = 1
		formData.value = []
		request()
	}

	const input = (e) => {
		formData.value = []
		parameter.searchKey = e
		request()
	}

	onReachBottom((e) => {
		parameter.current += 1
		request()
	})

	const details = (it) => {

		let obj = decodeURIComponent(JSON.stringify(it))
		uni.redirectTo({
			url: `/pages/view/InventoryCount/details?obj=${obj}`,
			// name=${it.name}&batchNumber=${it.batchNumber}&supplierId=${it.supplierId}&specification=${it.specification}&endDate=${it.endDate}&stockQty=${it.stockQty}&originalStockQty=${it.originalStockQty}&changeStockQty=${it.changeStockQty}
		})
	}

	const onClickScan = async () => {
		try {

			let res = await uni.scanCode({
				onlyFromCamera: true, // 仅允许相机扫描
				scanType: ['barCode'], // 指定扫描的码类型为二维码

			})
			parameter.current = 1
			parameter.searchKey = res.result
			await request(false)
		} catch (e) {
			if (e) {
				uni.showToast({
					title: '扫描失败',
					duration: 2000,
					icon: 'error',
				});
			}
		}
	}
</script>

<style lang="scss">
	.icon {
		width: 100%;
		text-align: center;

	}

	image {
		margin-left: 18rpx;
		width: 62rpx;
		height: 62rpx;
	}

	.forms_rows {
		display: flex;
		justify-content: space-between;
		align-items: center;

		.forms_label {
			margin: 6rpx 0;
		}

		.froms_icons {
			padding-right: 36rpx;
		}
	}
</style>